<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
         Promise 常用API
              1. p.then()   得到异步任务的正确结果
              2. p.catch()  捕获异常信息
              3. p.finally() 成功与否 否将执行（兼容性，最新浏览器支持）
        */
        // 见原型
        console.dir(Promise);
        let p = new Promise(function (resolve, reject) {
            setTimeout(() => {
                resolve('success');
                // reject('error');
            }, 100)
        });

        p.then(function (data) {
            console.log(data);
        })
            .catch(function (data) {
                console.log(data);
            })
            .finally(function () {
                console.log('finished');
            });
        console.log('--------------等效写法--------------')

        p.then(function (data) {
            console.log(data);
        }, function (data) {
            console.log(data);
        })
            .finally(function () {
                console.log('finished');
            });

    </script>
</body>

</html>